package com.homework.controller;

import com.homework.dto.Result;
import com.homework.entity.Student;
import com.homework.service.StudentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/student")
@RequiredArgsConstructor
public class StudentController {

    private final StudentService studentService;

    /**
     * 获取学生信息
     */
    @GetMapping("/info")
    public Result<Student> getStudentInfo() {
        return studentService.getFirstStudent();
    }

    /**
     * 更新学生信息
     */
    @PutMapping("/info")
    public Result<String> updateStudentInfo(@RequestBody Student student) {
        return studentService.updateStudent(student);
    }

    /**
     * 根据ID获取学生信息
     */
    @GetMapping("/{id}")
    public Result<Student> getStudentById(@PathVariable Long id) {
        return studentService.getStudentById(id);
    }

    /**
     * 获取所有学生信息
     */
    @GetMapping("/all")
    public Result<java.util.List<Student>> getAllStudents() {
        return studentService.getAllStudents();
    }

    /**
     * 创建学生信息
     */
    @PostMapping("/create")
    public Result<String> createStudent(@RequestBody Student student) {
        return studentService.createStudent(student);
    }
}